package com.itheima.Controller;

import com.itheima.Service.ClazzsService;
import com.itheima.entity.Clazz;
import com.itheima.entity.EmpParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class ClazzsController {
    @Autowired
    private ClazzsService clazzsService;
    //班级列表查询
    @GetMapping("/clazzs")
    public Result list(EmpParam empParam) {
        log.info("检查接收请求数据{}",empParam);
        //调用Service层
       PageBean pageBean = clazzsService.list(empParam);
        return Result.success(pageBean);
    }
    //删除班级
    @DeleteMapping("/clazzs/{id}")
    public Result deleteByID(@PathVariable String id) {
        //调用Service层
        clazzsService.deleteById(id);
        return Result.success();
    }
    //添加班级
    @PostMapping("/clazzs")
    public Result addClazz(@RequestBody Clazz clazz) {
        log.info("clazz:{}",clazz);
        //调用Service层对数据进行处理
        clazzsService.addClazz(clazz);
        return Result.success();
    }
    //根据id查询（回显功能）
    @GetMapping("/clazzs/{id}")
    public Result findById(@PathVariable String id) {
        //调用Service层
       Clazz clazz= clazzsService.findById(id);
        return Result.success(clazz);
    }
    //修改班级
    @PutMapping("/clazzs")
    public Result updateClazz(@RequestBody Clazz clazz) {
        //调用Service层
        log.info("--------------------clazz:{}",clazz);
        clazzsService.updateClazz(clazz);
        return  Result.success();
    }
    //查询所有班级
    @GetMapping("/clazzs/list")
    public Result getAllClazzs() {
        //调用Service层
        List<Clazz> list= clazzsService.getAllClazzs();
      return Result.success(list);
    }
}
